/*-
 * Copyright (c) 2006, 2007 FTS Team
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 4. Neither the name of the FTS Team nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 *      XMLConfigHandler.hpp
 *
 * $FTS$
 */
#ifndef _XML_CONFIG_HANDLER_HPP__
#define _XML_CONFIG_HANDLER_HPP__ 1

// Local Includes
#include <XMLHandler.hpp>

namespace FTSS // FullTextSearchSystem
{
// FWD
class IRConfig;

/**
  @class XMLHandler XMLParser.hpp <XMLParser.hpp>
  @brief Base abstract class for user handler
*/
class XMLConfigHandler:
  public XMLHandler
{
public:
	/**
	  @brief Constructor
	  @param oIIRConfig - IR library configuration
	*/
	XMLConfigHandler(IRConfig & oIIRConfig);

	/**
	  @brief A destructor
	*/
	~XMLConfigHandler() throw();
private:
	/** IR library configuration        */
	IRConfig                    & oIRConfig;
	/** Configuration stack             */
	STLW::vector<STLW::string>    vStack;
	/** Parser state for IRConfig       */
	UINT_32                       iParserState;
	/** Flag to search nested XML tags  */
	UINT_32                       iHasTags;
	/** Contents of element             */
	STLW::string                  sElementContents;

	/**
	  @brief Create key for config from current stack
	  @return Key with delimiters
	*/
	STLW::string CreateKeyFromStack();

	/**
	  @brief Check contents of element and
	  @return -1 if string is empty or string contains only spaces and CR/LF symbols, 0 - in other cases
	*/
	INT_32 CheckElementContents();

	/**
	  @brief Remove element from stack
	*/
	void PopStackElement();

	/**
	  @brief Start of XML Element
	  @param sElement -  Tag name
	  @param iLevel - Tag level
	  @param aAttr - tag attributes
	  @param iAttributes - number of attributes
	  @param iLine - Attrubute line
	  @param iColumn - Attrubute position
	*/
	INT_32 StartElement(CCHAR_P         sElement,
	                    const UINT_32 & iLevel,
	                    const XMLAttr * aAttr,
	                    const UINT_32 & iAttributes,
	                    const UINT_32 & iLine,
	                    const UINT_32 & iColumn) throw();

	/**
	  @brief End of XML Element
	  @param sElement -  Tag name
	  @param iLevel - Tag level
	  @param iLine - Attrubute line
	  @param iColumn - Attrubute position
	*/
	INT_32 EndElement(CCHAR_P         sElement,
	                  const UINT_32 & iLevel,
	                  const UINT_32 & iLine,
	                  const UINT_32 & iColumn)   throw();

	/**
	  @brief Characters insige a element
	  @param sData - Data
	  @param iLength - data length
	  @param iLevel - Tag level
	  @param iLine - Attrubute line
	  @param iColumn - Attrubute position
	*/
	INT_32 Characters(CCHAR_P         sData,
	                  const UINT_32 & iLength,
	                  const UINT_32 & iLevel,
	                  const UINT_32 & iLine,
	                  const UINT_32 & iColumn)   throw();

	/**
	  @brief XML Parse Error Handler
	  @param sReason - Error Description
	  @param iLevel - Line where error occured
	  @param iColumn - Column where error occured
	  @param iLine - Attrubute line
	  @param iColumn - Attrubute position
	*/
	void ParseError(CCHAR_P         sReason,
	                const UINT_32 & iLevel,
	                const UINT_32 & iLine,
	                const UINT_32 & iColumn)     throw();
};

} // namespace FTSS
#endif // _XML_HANDLER_HPP__
// End.
